<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:include page="../../common/assets_header.jsp"/>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<script src="<%=request.getContextPath()%>/assets/js/date-time/bootstrap-datepicker.min.js"></script>
<script src="<%=request.getContextPath()%>/assets/js/jqGrid/jquery.jqGrid.min.js"></script>
<script src="<%=request.getContextPath()%>/assets/js/jqGrid/i18n/grid.locale-en.js"></script>
<script>


jQuery(document).ready(function() {    
	
	loadGird();
	  
	
});

//初始化列表
function loadGird(){
	var grid_selector = "#grid-table";//列表对象
	var pager_selector = "#grid-pager";//列表分页对象
	jQuery(grid_selector).jqGrid({
		url : "<%=request.getContextPath()%>/sso/client_details/list_json",
		datatype : "json",
		height: 300,
		colNames:[/*' ',*/ ' ','Client Id','Client Secret','Resource Id','Scope','Web Server Redirect URL','创建时间'],
		colModel:[
		{name:'oauthClientDetailsId',index:'oauthClientDetailsId', width:60, sorttype:"int", hidden: true},
		{name:'clientId',index:'clientId',width:90,sortable:false},
		{name:'clientSecret',index:'clientSecret', width:90,sortable:false},
		{name:'resourceIds',index:'resourceIds', width:90,sortable:false},
		{name:'scope',index:'scope', width:90,sortable:false},
		{name:'webServerRedirectUri',index:'webServerRedirectUri', width:90,sortable:false},
		{name:'createTime',index:'createTime', width:90,sortable:false}
		], 
		viewrecords : true,
		rowNum:10,	
		
		rowList:[10,20,30],
		pager : pager_selector,
		altRows: true,
		multiselect: false,
		 multiboxonly: true,
		 loadComplete : function() {
			},
		caption: "client_details List",
		autowidth: true
	});
}

function delUser(){
	 var id = $("#grid-table").jqGrid('getGridParam', 'selrow');
	 var obj = null;
	 if(id){
		 obj = $("#grid-table").jqGrid('getRowData', id);
	 }else{
		 bootbox.alert({  
	            buttons: {  
	               ok: {label: '确认',className: 'btn-ok'  }  
	            },  
	            message: '请选择一行数据.',  
	            title: "提示",  
	        });
		 return;
	}
	 var susername = obj.clientId;
	 var id = obj.oauthClientDetailsId;
	bootbox.dialog({
		message : "<spring:message code="sure you want to delete"></spring:message>"+susername+"<spring:message code="what"></spring:message>",
		title : "<spring:message code="delete the user"></spring:message>",
		buttons : {
			confirm : {
				label : '<spring:message code="sure to delete"></spring:message>',
				className : "btn red btn-ok",
				callback : function() {
					$.ajax({
						type : "GET",
						url : "<%=request.getContextPath()%>/sso/client_details/del?id="+id,
						dataType : 'text',
						async : false,
						success : function(data) {
							if(data=="success"){
								$("#grid-table").trigger("reloadGrid"); 
							}else{
								noty({layout: 'center',text: "<spring:message code="delete the user failure"></spring:message>！",type: 'error', timeout: 2000 });
							}
						},
						error : function(data, status) {
							noty({layout: 'center',text: "<spring:message code="error"></spring:message>！",type: 'error', timeout: 2000 });
						}
					});
				}
			},
			cancel : {
				label : "<spring:message code="cancel"></spring:message>",
				className : "btn btn-danger"
			}
		}
	});
}

function add(){
	location.href="<%=request.getContextPath()%>/sso/client_details/form";
}
function edit(){
	var id = $("#grid-table").jqGrid('getGridParam', 'selrow');
	 var obj = null;
	 if(id){
		 obj = $("#grid-table").jqGrid('getRowData', id);
		 location.href="<%=request.getContextPath()%>/sso/client_details/form?id="+obj.oauthClientDetailsId;
	 }
	
}


function search(){
	var val = $("#searchId").val();
    var postData = $("#grid-table").jqGrid("getGridParam", "postData");
    $.extend(postData, {"searchValue":val});
	$("#grid-table").trigger("reloadGrid");
}

<%-- jQuery(document).ready(function() {    
	
    
   if("${list.sort}"=="asc"){
	   if("${list.orderBy}"=="dcreatetime"){
		  
		   $("#th_createtime").attr("class","sorting_asc");
			
	   }
   }
	if("${list.sort}"=="desc"){
	   if("${list.orderBy}"=="dcreatetime"){
		   $("#th_createtime").attr("class","sorting_desc");
	   }
   }
	  
	
});



function sortBy(obj,field){
	var cls = $(obj).attr("class");
	
	$("#sorting_column_order").val(field);
	
	if(cls=="sorting"){
		
		$("#sorting_asc_desc").val("asc");
		
	}else if(cls=="sorting_asc"){
		$("#sorting_asc_desc").val("desc");
	}else if(cls=="sorting_desc"){
		$("#sorting_asc_desc").val("asc");
	}
	
	$("#list_form").submit();
}

//新增或者编辑
function toEditPage(id){
	$("#list_form").attr("action","<%=request.getContextPath() %>/sso/client_details/form");
	$("#hiddenId").val(id);
	$("#list_form").submit();
}


function toListPage(pageIndex){
	$("#list_form").attr("action","<%=request.getContextPath() %>/sso/client_details/list");
	$("#iDisplayStart").val(pageIndex);
	$("#list_form").submit();
}

//删除
function delClient(id,clientId){
	bootbox.dialog({
		message : "<spring:message code="sure you want to delete"></spring:message>"+clientId+"<spring:message code="what"></spring:message>",
		title : "删除应用配置",
		buttons : {
			confirm : {
				label : '<spring:message code="sure to delete"></spring:message>',
				className : "btn red btn-ok",
				callback : function() {
					$.ajax({
						type : "GET",
						url : "<%=request.getContextPath()%>/sso/client_details/del?id="+id,
						dataType : 'text',
						async : false,
						success : function(data) {
							if(data=="success"){
								noty({layout: 'top',text: "删除成功！",type: 'success', timeout: 2000 });
								setTimeout(function(){window.location.reload();}, 1000);
							}else{
								noty({layout: 'top',text: "删除失败！",type: 'error', timeout: 2000 });
							}
						},
						error : function(data, status) {
							noty({layout: 'top',text: "<spring:message code="error"></spring:message>！",type: 'error', timeout: 2000 });
						}
					});
				}
			},
			cancel : {
				label : "<spring:message code="cancel"></spring:message>",
				className : "btn btn-danger"
			}
		}
	});
} --%>
</script>

</head>
<body >

	
		
		
		
		<%-- <form id="list_form" action="<%=request.getContextPath() %>/sso/client_details/list" method="post">
		<input type="hidden" name="sorting_column_order" id="sorting_column_order" value="${list.orderBy }"/>
		<input type="hidden" name="sorting_asc_desc"  id="sorting_asc_desc" value="${list.sort}"/>
		<input type="hidden" name="id" id="hiddenId"></input>
		<input type="hidden" name="clientId" id="clientIdId"></input>
		<input type="hidden" name="iDisplayStart" id="iDisplayStart" value=${list.currentPage } />
		<div class="page-content">


			<!-- BEGIN PAGE CONTAINER-->

			<div class="container-fluid">

				<!-- BEGIN PAGE HEADER-->

				<div class="row-fluid">

					<div class="span12">
						
					
						<h3 class="page-title">

							<!--系统用户管理 <small>欢迎您，admin!</small> -->

						</h3> 

						<ul class="breadcrumb">

							<li>

								<i class="icon-home"></i>

								<a href="index.html">Home</a> 

								<i class="icon-angle-right"></i>

							</li>

							<li>

								<a href="#">单点登录系统</a>

								<i class="icon-angle-right"></i>

							</li>

							<li><a href="#">应用配置</a></li>

						</ul>

						

					</div>

				</div>

				<!-- END PAGE HEADER-->

				<!-- BEGIN PAGE CONTENT-->

				

				<div class="row-fluid">
							<!-- BEGIN EXAMPLE TABLE PORTLET-->

						<!--<div class="portlet box light-grey">

							<div class="portlet-title">

								<div class="caption"><i class="icon-globe"></i>系统用户列表</div>

								<div class="tools">

									<a href="javascript:;" class="collapse"></a>

									<a href="#portlet-config" data-toggle="modal" class="config"></a>

									<a href="javascript:;" class="reload"></a>

									<a href="javascript:;" class="remove"></a>

								</div>

							</div>  -->

							<div class="portlet-body">

								<div class="clearfix">

									<p class="pull-left">
										
										<a href="#" onclick="toEditPage(null);" class="btn blue" >

										新增应用 <i class="icon-plus"></i>

										</a>
									</p>

									<div class="btn-group pull-right">

										<button class="btn dropdown-toggle" data-toggle="dropdown">Tools <i class="icon-angle-down"></i>

										</button>

										<ul class="dropdown-menu pull-right">

											<li><a href="#">Print</a></li>

											<li><a href="#">Save as PDF</a></li>

											<li><a href="#">Export to Excel</a></li>

										</ul>

									</div>

								</div>
								
								
						

												<div class="input-append hidden-phone">  

													<input class="m-wrap medium" size="10" name="serachValue" value="${serachValue }" type="text" /><button class="btn red">查询</button>

												</div>

								<table class="table table-striped table-bordered table-hover" id="user_grid">

									<thead>

										<tr>
											<th>Client Id</th>
											<th>Client Secret</th>
											<th>Resource Id</th>
											<th>Scope</th>
											<th>Web Server Redirect URL</th>
											<th  onclick="sortBy(this,'createTime');" class="sorting">创建时间</th>
											<th>Operation</th>
										</tr>

									</thead>
									<tbody>
										<c:forEach items="${list.resultList}" var="item" varStatus="status">
										
									
										<tr class="odd gradeX">

											<td>${item.clientId }</td>
											<td>${item.clientSecret }</td>
											<td>${item.resourceIds }</td>

											<td>${item.scope }</td>

											<td>${item.webServerRedirectUri }</td>
											
											<td>
											<c:if test="${!empty(item.createTime)}"><fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></c:if>
											</td>
											<td>
												<a href="#" onclick="toEditPage(${item.oauthClientDetailsId});"
												class="btn mini blue"><spring:message
														code="btn.common.edit"></spring:message></a> <a
												onclick="delClient(${item.oauthClientDetailsId},'${item.clientId}');" href="#"
												class="btn mini red"><spring:message
														code="btn.common.delete"></spring:message></a>
											</td>

										</tr>
										</c:forEach>
									</tbody>
									
								</table>
								<!-- 分页 -->
								<c:if test="${list.totalPages>1}">
									<div class="pagination" style="float:right">
										<ul>
											<li><a href="javascript:void();">总数：${list.totalRows}</a></li>
											<li <c:if test="${list.currentPage==1}">class="disabled"</c:if>>
												<c:if test="${list.currentPage>1}">
													<a href="javascript:toListPage(${list.currentPage-1});">上一页</a>
												</c:if>
												<c:if test="${list.currentPage==1}">
													<a href="#">上一页</a>
												</c:if>
											</li>
											<c:forEach begin="1" end="${list.totalPages}" var="item">
											<c:if test="${item < 4 || item==list.currentPage || item==list.currentPage+1 || item==list.currentPage+2 || item + 3 > list.totalPages }">
											<li <c:if test="${list.currentPage==item }">class="active"</c:if>><a href="javascript:toListPage(${item});">${item}</a></li></c:if>
											</c:forEach>
											<li <c:if test="${list.currentPage==list.totalPages}">class="disabled"</c:if>>
												<c:if test="${list.currentPage==list.totalPages}">
													<a href="#">下一页 </a>
												</c:if>
												<c:if test="${list.currentPage!=list.totalPages}">
													<a href="javascript:toListPage(${list.currentPage+1})">下一页 </a>
												</c:if>
											</li>
										</ul>
									</div>
								</c:if>
							</div>

						<!--  </div>-->

						</div>
			</div>


		</div>
		
		</form>
		

	 --%>

 <div class="page-content">
		<div class="page-header">
			<!-- <h1>
				jqGrid
				<small>
					<i class="icon-double-angle-right"></i>
					Dynamic tables and grids using jqGrid plugin
				</small>
			</h1> -->
			<button class="btn btn-xs btn-primary" onclick="add();" id="newBtn">New</button>
			<button class="btn btn-xs btn-primary" onclick="edit();" id="editBtn">Edit</button>
			<button class="btn btn-xs btn-primary" onclick="delUser();" id="deleteBtn">Delete</button>
		</div>
		
		
		<div class="row">
			<div class="col-xs-12">
			<div class="form-group">
				<input type="text" id="searchId" maxlength="30"  class="m-wrap" />
			
				<button class="btn btn-xs btn-primary" onclick="search();" id="searchBtn">Search</button>
			</div>
			
			<!-- 列表 -->
			<table id="grid-table"></table>
			<!-- 分页 -->
			<div id="grid-pager"></div>
		</div>
		</div>
	</div>


</body>